/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers;

import DAO.PaymentDAO;
import DAO.RequestDAO;
import Models.Payment;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author phuong
 */
@ManagedBean
@RequestScoped
public class PaymentControl {

    List<Payment> listPayment = new ArrayList<Payment>();
    List<Payment> listPaymentExpire = new ArrayList<Payment>();

    public List<Payment> getListPaymentExpire() throws Exception {
        return listPaymentExpire=PaymentDAO.getListPaymentCompanyExpires();
    }

    public void setListPaymentExpire(List<Payment> listPaymentExpire) {
        this.listPaymentExpire = listPaymentExpire;
    }

    public List<Payment> getListPayment() throws Exception {
        return listPayment = PaymentDAO.getListPaymentCompany();
    }

    public void setListPayment(List<Payment> listPayment) {
        this.listPayment = listPayment;
    }
    List<Payment> listD = new ArrayList<Payment>();
    List<Payment> listA = new ArrayList<Payment>();

    public List<Payment> getListAEx() throws Exception {
        return listAEx = PaymentDAO.getListPaymentAdvertiseExpires();
    }

    public void setListAEx(List<Payment> listAEx) {
        this.listAEx = listAEx;
    }

    public List<Payment> getListDEx() throws Exception {
        return listDEx = PaymentDAO.getListPaymentDriverExpires();
    }

    public void setListDEx(List<Payment> listDEx) {
        this.listDEx = listDEx;
    }
    List<Payment> listDEx = new ArrayList<Payment>();
    List<Payment> listAEx = new ArrayList<Payment>();
    public List<Payment> getListA() throws Exception {
        return listA = PaymentDAO.getListPaymentAdvertise();
    }

    public void setListA(List<Payment> listA) {
        this.listA = listA;
    }

    public List<Payment> getListD() throws Exception {
        return listD = PaymentDAO.getListPaymentDriver();
    }

    public void setListD(List<Payment> listD) {
        this.listD = listD;
    }

    //public void deletePayment(int id) throws Exception {PaymentDAO.deletePayment(id);}
//    public void checkTrue(int id) throws Exception{PaymentDAO.checkTruePayment(id);}
//    public void checkFalse(int id) throws Exception{PaymentDAO.checkFalsePayment(id);}
    public void editSubmit() throws Exception {
        Payment pay = (Payment) (FacesContext.getCurrentInstance().getExternalContext().
                getRequestMap().get("paymentBean"));
        PaymentDAO.editPayment(pay);
    }

    public void selectedID(int selectedID) {
        ExternalContext e = FacesContext.getCurrentInstance().getExternalContext();
        HttpSession session = (HttpSession) e.getSession(true);
        session.setAttribute("selectedID", selectedID);
    }

    public void deletePay() throws Exception {
        ExternalContext e = FacesContext.getCurrentInstance().getExternalContext();
        HttpSession session = (HttpSession) e.getSession(true);
        int id = Integer.parseInt(session.getAttribute("selectedID").toString());
        PaymentDAO.deletePayment(id);
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Information: ", "Attribute has been deleted !"));
    }

    /**
     * Creates a new instance of PaymentControl
     */
    public PaymentControl() {
    }
}
